#!/usr/bin/env bash

#add java
if [ -n "$JAVA_HOME" ];
then
  echo   "jdk已存在"
else
  echo "安装JDK1.8..."
  wget https://d6.injdk.cn/openjdk/openjdk/11/openjdk-11+28_linux-x64_bin.tar.gz -P /opt -N

  tar -zxf  /opt/openjdk-11*linux-x64*.tar.gz -C /opt/
  path2=`ls -F /opt | grep '/$'| grep jdk-11 | sed 's/.$//'`
  chmod -R +x /opt/$path2

  echo -e "\n# JAVA_HOME \n \
export JAVA_HOME=/opt/$path2 \n \
export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar \n \
export PATH=\$JAVA_HOME/bin:\$PATH " | sudo tee -a /etc/profile
  source /etc/profile
  ln -snf $JAVA_HOME/bin/java /usr/bin/java
fi

# curl -fsSL http://dev8.cn:8000/static/ops/jdk.sh | bash